package com.lins.framework.widget;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.TextView;

import com.lins.framework.R;

/**
 * Created by Administrator on 2018/3/6.
 */

public class MyLoadingDialog extends ProgressDialog {

    private TextView idTvLoadMsg;
    private String msg;


    public MyLoadingDialog(Context context, String msg) {
        super(context, R.style.MyLoadingDialog);
        this.msg = msg;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init(getContext());
    }

    @Override
    public void setMessage(CharSequence message) {
        super.setMessage(message);
        idTvLoadMsg.setText(message);
    }

    private void init(Context context) {
        //设置不可取消，点击其他区域不能取消，实际中可以抽出去封装供外包设置
//        setCancelable(false);
        setCanceledOnTouchOutside(false);

        setContentView(R.layout.weidget_loading);
        idTvLoadMsg = findViewById(R.id.id_tv_load_msg);
        idTvLoadMsg.setText(msg);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }

    @Override
    public void show() {
        super.show();
    }
}
